/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.persistence;

import opiam.admin.faare.service.UserContext;

import org.apache.log4j.Logger;

import java.util.ArrayList;

/**
 * Lazy loading for binary attributes, such as photo or certificate.
 */
public class LazyBytesCollection extends LazyStringCollection
{
    /** Log4J. */
    private static Logger _logger = Logger.getLogger(LazyBytesCollection.class.getName());

   /**
     * Creates a new LazyBytesCollection object.
     *
     * @param enclosing Dname of entry containing attribute to load.
     * @param atts Attribute to load.
     * @param auserContext Connected user context.
     */
    public LazyBytesCollection(String enclosing, ArrayList atts,
        UserContext auserContext)
    {
        super(enclosing, atts, auserContext);
    }

    /**
     * Loads values.
     */
    @Override
	protected void lazyLoad()
    {
        try
        {
            ArrayList bvalues = (ArrayList) PersistenceLDAP.loadBinaryAttribute(getDn(), getAtt(),
                    getUserContext());
            _logger.debug("lazyLoad temp.size() : " + bvalues.size());

            setLoaded(true);
            setValues(bvalues);
        }
        catch (Exception e)
        {
            if (_logger.isDebugEnabled())
            {
                _logger.debug("Trace", e);
            }

            throw new RuntimeException(
                "PersistenceException for lazy loaded object\n" + e);
        }
    }
}
